import { BasicColumn, FormSchema } from "/@/components/Table";
import { render } from "/@/utils/common/renderUtils";


//订单列表 - 状态转译 -------------------------------------------------------------------------
const statusFmt = ({text, record}) => {
  if (text && record.type !== '1') {
    let color = '';
    switch ( text ) {
      case "2":
        color = 'yellow' // 预留
        break;
      case "3":
        color = 'red'; // 确认
        break;
      case "4":
        color = 'gray'; // 取消
        break;
    }
    return render.renderTag(render.renderDict(text, 'reserveType'), color)
  } else {
    return text
  }
}

//名称格式化
const nameFmt = ({text, record}) => {
  if (text && record.type !== '1') {
    return text
  } else {
    return record.number + " " + record.name + record.ful
  }
}

//用餐时间
const mealTimeFmt = ({text, record}) => {
  if (text && record.type !== '1') {
    return render.renderDict(text, 'mealTime')
  } else {
    return text
  }
}

//用餐时间
const sexFmt = ({text, record}) => {
  if (text && record.type !== '1') {
    return render.renderDict(text, 'sex')
  } else {
    return text
  }
}
//---------------------------------------------

/**
 * name           lunch      dinner   occupy     reserv   cannel                         count
 * 包厢名称         中餐       晚餐      预留        确认      取消                            合计
 * 预订日期         用餐时间    预定类型   客户姓名    客户电话   性别     客户经理     更新时间      更新人
 * reserve_date   mealTime   type     realname   tel      sex     createName  updateTime  updateName
 */
export const columns: BasicColumn[] = [
  { title: "包厢名称/预订日期", dataIndex: "name", width: 140, align: "left", customRender: nameFmt },
  { title: "中餐", dataIndex: "lunch", width: 80, customRender: mealTimeFmt ,},
  { title: "晚餐", dataIndex: "dinner", width: 80, customRender: statusFmt, },
  { title: "预留", dataIndex: "occupy", width: 100 },
  { title: "确认", dataIndex: "reserv", width: 100 },
  { title: "取消", dataIndex: "cannel", width: 80, customRender: sexFmt,},
  { title: "客户经理", dataIndex: "manager", width: 80},
  { title: "订厢人员", dataIndex: "createName", width: 80},
  { title: "更新时间", dataIndex: "updateTime", width: 100},
  { title: "合计", dataIndex: "count", width: 80 },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: "状态",
    field: "stat",
    component: "JDictSelectTag",
    componentProps: {
      dictCode: "stateType",
      placeholder: "请选择状态",
      stringToNumber: true
    },
  },
  {
    label: "包厢名称",
    field: "name",
    component: "Input"
  }
];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: "", field: "id", component: "Input", show: false },
  {
    label: "状态",
    field: "stat",
    component: "JDictSelectTag",
    componentProps: {
      dictCode: "stateType",
      placeholder: "请选择状态",
      stringToNumber: true
    },
  },
  {
    label: "包厢编号",
    field: "number",
    component: "Input"
  },
  {
    label: "包厢名称",
    field: "name",
    component: "Input"
  },
  {
    label: "排序",
    field: "sort",
    component: "Input"
  },
];
